home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 April / macformat-049.iso / mac / Shareware Plus / Developers / dropg++ / usr / include / sys / tty.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  8.3 KB  |  218 lines  |  [TEXT/R*ch]

  1. /*-
  2.  * Copyright (c) 1982, 1986, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  * (c) UNIX System Laboratories, Inc.
  5.  * All or some portions of this file are derived from material licensed
  6.  * to the University of California by American Telephone and Telegraph
  7.  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  8.  * the permission of UNIX System Laboratories, Inc.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  *
  38.  *    @(#)tty.h    8.6 (Berkeley) 1/21/94
  39.  */
  40.  
  41. #include <sys/termios.h>
  42. #include <sys/select.h>        /* For struct selinfo. */
  43.  
  44. /*
  45.  * Clists are character lists, which is a variable length linked list
  46.  * of cblocks, with a count of the number of characters in the list.
  47.  */
  48. struct clist {
  49.     int    c_cc;        /* Number of characters in the clist. */
  50.     char    *c_cf;        /* Pointer to the first cblock. */
  51.     char    *c_cl;        /* Pointer to the last cblock. */
  52. };
  53.  
  54. /*
  55.  * Per-tty structure.
  56.  *
  57.  * Should be split in two, into device and tty drivers.
  58.  * Glue could be masks of what to echo and circular buffer
  59.  * (low, high, timeout).
  60.  */
  61. struct tty {
  62.     struct    clist t_rawq;        /* Device raw input queue. */
  63.     long    t_rawcc;        /* Raw input queue statistics. */
  64.     struct    clist t_canq;        /* Device canonical queue. */
  65.     long    t_cancc;        /* Canonical queue statistics. */
  66.     struct    clist t_outq;        /* Device output queue. */
  67.     long    t_outcc;        /* Output queue statistics. */
  68.     char    t_line;            /* Interface to device drivers. */
  69.     dev_t    t_dev;            /* Device. */
  70.     int    t_state;        /* Device and driver (TS*) state. */
  71.     int    t_flags;        /* Tty flags. */
  72.     struct    pgrp *t_pgrp;        /* Foreground process group. */
  73.     struct    session *t_session;    /* Enclosing session. */
  74.     struct    selinfo t_rsel;        /* Tty read/oob select. */
  75.     struct    selinfo t_wsel;        /* Tty write select. */
  76.     struct    termios t_termios;    /* Termios state. */
  77.     struct    winsize t_winsize;    /* Window size. */
  78.                     /* Start output. */
  79.     void    (*t_oproc) __P((struct tty *));
  80.                     /* Stop output. */
  81.     void    (*t_stop) __P((struct tty *, int));
  82.                     /* Set hardware state. */
  83.     int    (*t_param) __P((struct tty *, struct termios *));
  84.     void    *t_sc;            /* XXX: net/if_sl.c:sl_softc. */
  85.     short    t_column;        /* Tty output column. */
  86.     short    t_rocount, t_rocol;    /* Tty. */
  87.     short    t_hiwat;        /* High water mark. */
  88.     short    t_lowat;        /* Low water mark. */
  89.     short    t_gen;            /* Generation number. */
  90. };
  91.  
  92. #define    t_cc        t_termios.c_cc
  93. #define    t_cflag        t_termios.c_cflag
  94. #define    t_iflag        t_termios.c_iflag
  95. #define    t_ispeed    t_termios.c_ispeed
  96. #define    t_lflag        t_termios.c_lflag
  97. #define    t_min        t_termios.c_min
  98. #define    t_oflag        t_termios.c_oflag
  99. #define    t_ospeed    t_termios.c_ospeed
  100. #define    t_time        t_termios.c_time
  101.  
  102. #define    TTIPRI    25            /* Sleep priority for tty reads. */
  103. #define    TTOPRI    26            /* Sleep priority for tty writes. */
  104.  
  105. #define    TTMASK    15
  106. #define    OBUFSIZ    100
  107. #define    TTYHOG    1024
  108.  
  109. #ifdef KERNEL
  110. #define    TTMAXHIWAT    roundup(2048, CBSIZE)
  111. #define    TTMINHIWAT    roundup(100, CBSIZE)
  112. #define    TTMAXLOWAT    256
  113. #define    TTMINLOWAT    32
  114. #endif
  115.  
  116. /* These flags are kept in t_state. */
  117. #define    TS_ASLEEP    0x00001        /* Process waiting for tty. */
  118. #define    TS_ASYNC    0x00002        /* Tty in async I/O mode. */
  119. #define    TS_BUSY        0x00004        /* Draining output. */
  120. #define    TS_CARR_ON    0x00008        /* Carrier is present. */
  121. #define    TS_FLUSH    0x00010        /* Outq has been flushed during DMA. */
  122. #define    TS_ISOPEN    0x00020        /* Open has completed. */
  123. #define    TS_TBLOCK    0x00040        /* Further input blocked. */
  124. #define    TS_TIMEOUT    0x00080        /* Wait for output char processing. */
  125. #define    TS_TTSTOP    0x00100        /* Output paused. */
  126. #define    TS_WOPEN    0x00200        /* Open in progress. */
  127. #define    TS_XCLUDE    0x00400        /* Tty requires exclusivity. */
  128.  
  129. /* State for intra-line fancy editing work. */
  130. #define    TS_BKSL        0x00800        /* State for lowercase \ work. */
  131. #define    TS_CNTTB    0x01000        /* Counting tab width, ignore FLUSHO. */
  132. #define    TS_ERASE    0x02000        /* Within a \.../ for PRTRUB. */
  133. #define    TS_LNCH        0x04000        /* Next character is literal. */
  134. #define    TS_TYPEN    0x08000        /* Retyping suspended input (PENDIN). */
  135. #define    TS_LOCAL    (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
  136.  
  137. /* Character type information. */
  138. #define    ORDINARY    0
  139. #define    CONTROL        1
  140. #define    BACKSPACE    2
  141. #define    NEWLINE        3
  142. #define    TAB        4
  143. #define    VTAB        5
  144. #define    RETURN        6
  145.  
  146. struct speedtab {
  147.     int sp_speed;            /* Speed. */
  148.     int sp_code;            /* Code. */
  149. };
  150.  
  151. /* Modem control commands (driver). */
  152. #define    DMSET        0
  153. #define    DMBIS        1
  154. #define    DMBIC        2
  155. #define    DMGET        3
  156.  
  157. /* Flags on a character passed to ttyinput. */
  158. #define    TTY_CHARMASK    0x000000ff    /* Character mask */
  159. #define    TTY_QUOTE    0x00000100    /* Character quoted */
  160. #define    TTY_ERRORMASK    0xff000000    /* Error mask */
  161. #define    TTY_FE        0x01000000    /* Framing error or BREAK condition */
  162. #define    TTY_PE        0x02000000    /* Parity error */
  163.  
  164. /* Is tp controlling terminal for p? */
  165. #define    isctty(p, tp)                            \
  166.     ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
  167.  
  168. /* Is p in background of tp? */
  169. #define    isbackground(p, tp)                        \
  170.     (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
  171.  
  172. #ifdef KERNEL
  173. extern    struct ttychars ttydefaults;
  174.  
  175. /* Symbolic sleep message strings. */
  176. extern     char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[];
  177.  
  178. int     b_to_q __P((char *cp, int cc, struct clist *q));
  179. void     catq __P((struct clist *from, struct clist *to));
  180. void     clist_init __P((void));
  181. int     getc __P((struct clist *q));
  182. void     ndflush __P((struct clist *q, int cc));
  183. int     ndqb __P((struct clist *q, int flag));
  184. char    *nextc __P((struct clist *q, char *cp, int *c));
  185. int     putc __P((int c, struct clist *q));
  186. int     q_to_b __P((struct clist *q, char *cp, int cc));
  187. int     unputc __P((struct clist *q));
  188.  
  189. int     nullmodem __P((struct tty *tp, int flag));
  190. int     tputchar __P((int c, struct tty *tp));
  191. int     ttioctl __P((struct tty *tp, int com, void *data, int flag));
  192. int     ttread __P((struct tty *tp, struct uio *uio, int flag));
  193. void     ttrstrt __P((void *tp));
  194. int     ttselect __P((dev_t device, int rw, struct proc *p));
  195. void     ttsetwater __P((struct tty *tp));
  196. int     ttspeedtab __P((int speed, struct speedtab *table));
  197. int     ttstart __P((struct tty *tp));
  198. void     ttwakeup __P((struct tty *tp));
  199. int     ttwrite __P((struct tty *tp, struct uio *uio, int flag));
  200. void     ttychars __P((struct tty *tp));
  201. int     ttycheckoutq __P((struct tty *tp, int wait));
  202. int     ttyclose __P((struct tty *tp));
  203. void     ttyflush __P((struct tty *tp, int rw));
  204. void     ttyinfo __P((struct tty *tp));
  205. int     ttyinput __P((int c, struct tty *tp));
  206. int     ttylclose __P((struct tty *tp, int flag));
  207. int     ttymodem __P((struct tty *tp, int flag));
  208. int     ttyopen __P((dev_t device, struct tty *tp));
  209. int     ttyoutput __P((int c, struct tty *tp));
  210. void     ttypend __P((struct tty *tp));
  211. void     ttyretype __P((struct tty *tp));
  212. void     ttyrub __P((int c, struct tty *tp));
  213. int     ttysleep __P((struct tty *tp,
  214.         void *chan, int pri, char *wmesg, int timeout));
  215. int     ttywait __P((struct tty *tp));
  216. int     ttywflush __P((struct tty *tp));
  217. #endif
  218.